package com.qf.controller;/*
 *徐韬
 *2021/11/5
 *8:19
 */

import com.qf.cache.paramsCache;
import com.qf.dto.R;
import com.qf.pojo.Params;
import com.qf.service.paramsService;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/param")
@Api(tags = "动态参数控制")
public class paramsController {
    private paramsCache paramsCache;
    private paramsService paramsService;
@Autowired
    public void setParamsService(com.qf.service.paramsService paramsService) {
        this.paramsService = paramsService;
    }

    @Autowired
    public void setParamsCache(com.qf.cache.paramsCache paramsCache) {
        this.paramsCache = paramsCache;
    }
    @GetMapping("/show")
    public R show(){
        List<Params> params = paramsCache.getfinlAll();
        return R.setOk(params);
    }
    @GetMapping("/showByName/{name}")
    public R showByName(@PathVariable String name){
        Params params = paramsCache.getById(name);
        return R.setOk(params);

    }
    @PostMapping("/add")
    public R addParams( Params params){
     paramsService.addParams(params);
     return R.setOk();
    }
    @PostMapping("/update")
    public R upddate(@RequestBody Params params){
    paramsService.updateParams(params);
    return R.setOk();

    }
    @DeleteMapping("/delete")
    public R delete(@RequestBody Map map){
        List<Integer> names =(List<Integer>) map.get("names");
        paramsService.deleteParams(names);
        return R.setOk();


    }
}
